# -*- coding: utf-8 -*-
from venv1.Page.policyIfmComPage import policyIfmComPage
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import xlrd
class Recheck():
    def __init__(self,driver):
        self.driver=driver
        self.policyIfmComPage=policyIfmComPage(self.driver)
    def Recheck(self,PolicyNo):
        window1 = self.driver.window_handles
        self.driver.switch_to.window(window1[-1])
        time.sleep(1)
        self.policyIfmComPage.btnRecheck().click()
        time.sleep(1)
        self.policyIfmComPage.inpPolicyNo().send_keys(PolicyNo)
        time.sleep(1)
        self.policyIfmComPage.btnPolicyGet().click()
        time.sleep(1)
        # 切換窗口
        window1 = self.driver.window_handles
        self.driver.switch_to.window(window1[-1])
        time.sleep(1)
        # 點擊彈框確認按鈕
        self.policyIfmComPage.btnSubmit().click()
        time.sleep(1)
        try:
            # 切換窗口
            window2 = self.driver.window_handles
            self.driver.switch_to.window(window2[-1])
            time.sleep(1)
            # 選擇目標數據
            self.policyIfmComPage.TargetData().click()
            time.sleep(2)
            window3 = self.driver.window_handles
            self.driver.switch_to.window(window3[-1])
            time.sleep(1)

            ActionChains(self.driver).key_down(Keys.CONTROL).send_keys('W').key_up(Keys.CONTROL).perform()
            time.sleep(1)
            self.policyIfmComPage.inpRecheckResult().click()
            time.sleep(1)
            filename = r'..\TestData\Data.xls'
            excel_open = xlrd.open_workbook(filename)
            table = excel_open.sheet_by_name('Sheet1')


            row_content = table.row_values(2)
            RecheckResult = row_content[9]
            if RecheckResult=='通过':
                self.policyIfmComPage.btnPassone().click()
                time.sleep(1)
                self.policyIfmComPage.btnRecheckSubmit().click()
                time.sleep(1)
                self.policyIfmComPage.btnRecheckSubmit1().click()
                time.sleep(5)
                self.policyIfmComPage.btnSubmit2().click()
                time.sleep(2)

            else:
                self.policyIfmComPage.btnReturned().click()
                time.sleep(1)
            self.driver.close()
            time.sleep(1)
            window4 = self.driver.window_handles
            self.driver.switch_to.window(window4[-1])
            time.sleep(1)
















        except Exception as msg:
            print('error:',msg)